<?php

/**
 * 程序测试类
 * 
 * @package    01CMS
 * @subpackage system
 * @author     rolong at vip.qq.com
 * @version    1.0.0
 * @link       http://www.01cms.com
 */

class Test
{
	public $startTime = 0;
	public $stopTime = 0;
	public $spentTime = 0;

	/**
	 * 初始化
	 * 
	 * @return 	void
	 * @access 	public
	 */
	function init ()
	{
		$this->startTime = 0;
		$this->endTime = 0;
		$this->spentTime = 0;
	}

	/**
	 * 开始时间
	 * 
	 * @return 	void
	 * @access 	public
	 */
	function startTime ()
	{
		$this->startTime = microtime();
	}

	/**
	 * 结束时间
	 * 
	 * @return 	void
	 * @access 	public
	 */
	function stopTime ()
	{
		$this->stopTime = microtime();
	}

	/**
	 * 所用时间
	 * 
	 * @return 	string
	 * @access 	public
	 */
	function spentTime ()
	{
		if ($this->spentTime)
		{
			return $this->spentTime;
		}
		else
		{
			$startMicro = substr($this->startTime, 0, 10);
			
			$startSecond = substr($this->startTime, 11, 10);
			
			$stopMicro = substr($this->stopTime, 0, 10);
			
			$stopSecond = substr($this->stopTime, 11, 10);
			
			$start = doubleval($startMicro) + $startSecond;
			
			$stop = doubleval($stopMicro) + $stopSecond;
			
			$this->spentTime = $stop - $start;
			
			return substr($this->spentTime, 0, 8) . "(s)";
		}
	}
}
